package com.mxpio.erp.technology.controller;

import com.mxpio.erp.common.technology.entity.ItemDesignFileAlter;
import com.mxpio.erp.common.technology.service.ItemDesignFileAlterService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "ItemDesignFileAlterController", description = "产品设计图档变更")
@RestController
@RequestMapping("/erp/common/item/designfile/alter/")
public class ItemDesignFileAlterController {

	@Autowired
	private ItemDesignFileAlterService service;

	@GetMapping("list")
	@Operation(summary = "产品设计图档变更列表", description = "获取产品设计图档变更列表", method = "GET")
	public Result<List<ItemDesignFileAlter>> list(Criteria criteria)  {
		List<ItemDesignFileAlter> itemDesignFileAlters = service.list(ItemDesignFileAlter.class, criteria);
		return Result.OK(itemDesignFileAlters);
	}

	@GetMapping("page")
	@Operation(summary = "产品设计图档变更列表", description = "获取产品设计图档变更列表", method = "GET")
	public Result<Page<ItemDesignFileAlter>> page(Criteria criteria, Integer pageSize, Integer pageNo) {
		Pageable page = PageRequest.of(pageNo-1, pageSize);
		Page<ItemDesignFileAlter> itemDesignFileAlters = service.listPage(ItemDesignFileAlter.class, page, criteria);
		return Result.OK(itemDesignFileAlters);
	}
	@RequestMapping("edit")
	@Operation(summary = "编辑产品设计图档变更申请单", description = "编辑产品设计图档变更申请单")
	public Result<ItemDesignFileAlter> edit(@RequestBody ItemDesignFileAlter itemDesignFileAlter) {
		service.update(itemDesignFileAlter);
		return Result.OK(itemDesignFileAlter);
	}

	@GetMapping("list/{alterCode}")
	@Operation(summary = "根据编码-获取变更单信息", description = "根据编码-获取变更单信息", method = "GET")
	public Result<ItemDesignFileAlter> getById(@PathVariable(name = "alterCode", required = true) String alterCode) {
		ItemDesignFileAlter itemDesignFileAlter = service.getByIdWith(alterCode);
		return Result.OK(itemDesignFileAlter);
	}

/*	@PostMapping("add")
	@Operation(summary = "新增产品设计图档变更", description = "新增产品设计图档变更", method = "POST")
	public Result<ItemDesignFileAlter> add(@RequestBody ItemDesignFileAlter itemDesignFileAlter) {
		itemDesignFileAlterSerivce.save(itemDesignFileAlter);
		return Result.OK(itemDesignFileAlter);
	}

	@RequestMapping("edit")
	@Operation(summary = "编辑产品设计图档变更", description = "编辑产品设计图档变更（全量）")
	public Result<ItemDesignFileAlter> edit(@RequestBody ItemDesignFileAlter itemDesignFileAlter) {
		itemDesignFileAlterSerivce.update(itemDesignFileAlter);
		return Result.OK(itemDesignFileAlter);
	}*/

	@GetMapping("audit_pass/{alterCode}/{result}")
	@Operation(summary = "产品设计图档变更-审核结果回调", description = "产品设计图档变更-审核结果回调", method = "GET")
	public Result<ItemDesignFileAlter> auditPass(@PathVariable(name = "alterCode", required = true) String alterCode,@PathVariable(name = "result", required = true) String result ) {
		return service.auditPass(alterCode,result);
	}
}
